package se.hiq.wineo.client.widgets.common;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

/**
 * This Widgets presents a field name and a field value to the user. The field value is editable.
 * 
 * @author joakimsah
 *
 */
public class FieldWidget extends Composite {
	
	// Widgets in this Composite
	private Grid mainPanel;
	private Label nameLabel;
	private TextBox valueTextBox;
	
	public FieldWidget(String name, String value, String labelWidth) {
		mainPanel = new Grid(1, 2);
		nameLabel = new Label(name);
		nameLabel.setWidth(labelWidth);
		valueTextBox = new TextBox();
		valueTextBox.setText(value);
		
		mainPanel.setWidget(0, 0, nameLabel);
		mainPanel.setWidget(0, 1, valueTextBox);
		initWidget(mainPanel);
	}
	
	/**
	 * Get value from input part of this component
	 * 
	 * @return
	 */
	public String getValue() {
		return valueTextBox.getText();
	}
	
	/**
	 * Set value of input part of this component
	 * 
	 * @param value
	 */
	public void setValue(String value) {
		valueTextBox.setText(value);
	}
	
	/**
	 * Set whether the input part of this component is enabled
	 * 
	 * @param enabled true/false
	 */
	public void setEnabled(boolean enabled) {
		valueTextBox.setEnabled(enabled);
	}

}
